package CLASS;

public class Order {
    //属性私有化
        private int orderNum;
        private double money;
        private String goods[];

        //添加toString方法
    @Override
    public String toString() {
        return "Order{" +
                "orderNum=" + orderNum +
                ", money=" + money +
                ", goods='" + goods + '\'' +
                '}';
    }

    //添加无参构造方法
    private Order(){
        //在无参构造方法中设置初始值·
        orderNum = 10001;
        money = 1000;
        goods = new String[]{"苹果","香蕉","哈密瓜"};
    }

    //添加有参构造方法,并为属性赋值
    private Order(int orderNum,double money,String[] goods){
        this.orderNum = orderNum;
        this.money = money;
        this.goods = goods;
    }

    //加封装方法
    public int getOrderNum() {
        return orderNum;
    }

    //加封装方法
    public void setOrderNum(int orderNum) {
        this.orderNum = orderNum;
    }

    public static void main(String[] args) {

        //测试无参构造方法
        Order order1 = new Order();
        System.out.println("无参构造：" + order1);

        //有参构造方法
        Order order2 = new Order(3,9.9, new String[]{"苹果", "哈密瓜", "香蕉"});
        System.out.println("有参构造：" + order2);
    }
}
